﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;

namespace MLY
{
  public static class SessParam
  {
    public static bool IsClient
    {
      get
      {
        if (Session["IsClient"] == null)
          return false;
        return (bool)Session["IsClient"];
      }
      set
      {
        Session["IsClient"] = value;
      }
    }

    private static HttpSessionState Session
    {
      get
      {
        return HttpContext.Current.Session;
      }
    }

    public static int MasterWorkWorderID
    {
      set
      {
        Session["MasterWorkWorderID"] = value;
      }
    }

    public static string EditFormErrorMessage
    {
      get
      {
        if (Session["EditFormErrorMessage"] == null)
          return "";
        return Session["EditFormErrorMessage"].ToString();
      }
      set
      {
        Session["EditFormErrorMessage"] = value;
      }
    }

    public static string CustomerId
    {
      get
      {
        if (Session["CustomerId"] == null)
          return "";
        return Session["CustomerId"].ToString();
      }
      set
      {
        Session["CustomerId"] = value;
      }
    }

    public static string ContractorID
    {
      get
      {
        if (Session["ContractorID"] == null)
          return "";
        return Session["ContractorID"].ToString();
      }
      set
      {
        Session["ContractorID"] = value;
      }
    }

    public static bool WorkOrderEditing
    {
      get
      {
        object obj = Session["WorkOrderEditing"];
        if (obj == null)
          return false;
        return (bool)obj;
      }
      set
      {
        Session["WorkOrderEditing"] = value;
      }
    }

    public static int UserId
    {
      get
      {
        int? i = (int?)Session["UserId"];
        return (i != null ? (int)i : -1);
      }
      set
      {
        Session["UserId"] = value;
      }
    }

    public static string FullName
    {
      get
      {
        string i = (string)Session["FullName"];
        return (string.IsNullOrEmpty(i) ? "" : i);
      }
      set
      {
        Session["FullName"] = value;
      }
    }

    public static int OrganizationId
    {
      get
      {
        int? i = (int?)Session["OrganizationId"];
        return (i != null ? (int)i : -1);
      }
      set
      {
        Session["OrganizationId"] = value;
      }
    }

    public static string OrganizationName
    {
      get
      {
        string i = (string)Session["OrganizationName"];
        return (string.IsNullOrEmpty(i) ? "" : i);
      }
      set
      {
        Session["OrganizationName"] = value;
      }
    }

    public static string Culture
    {
      get
      {
        return GetStr("Culture", "en");
      }
      set
      {
        Session["Culture"] = value;
      }
    }

    private static string GetStr(string key, string defaultValue)
    {
      string result = (string)Session[key];
      if (string.IsNullOrEmpty(result))
        return defaultValue;
      else
        return result;
    }

    public static int RoleId
    {
      get
      {
        int? i = (int?)Session["RoleId"];
        return (i != null ? (int)i : -1);
      }
      set
      {
        Session["RoleId"] = value;
      }
    }
  }

}
